package com.shop2cn.iapi.wxcomponent.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.wxcomponent.parameter.RemarkBean;
import com.shop2cn.iapi.wxcomponent.service.RemarkCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.database.model.Mchapp;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.TestDataManager;
/**
*添加备注
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_Remark{
	private static RemarkBean remarkBean;
	private static RemarkCall remarkCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("添加备注");
	}
	

	@Before
	public void caseUp() {
		remarkBean=new RemarkBean();
		remarkCall=new RemarkCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(remarkCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_Remark_001() {
		Logger.start(true,"添加备注");
		try {
			DefGodMchWapper DefGodMchWapper=new DefGodMchWapper();
			Mchapp defmchapp = DefGodMchWapper.selectMchappByExample(null).get(0);
			remarkBean.setMark("testmark"+TestDataManager.getRandomIntNum(3));
			remarkBean.setMchId(defmchapp.getMchId());
			remarkCall.setData(remarkBean);
			remarkCall.callService();			
			Logger.verifyEquals("200", remarkCall.getString("code"), "验证返回code");
			defmchapp = DefGodMchWapper.selectMchappByExample(defmchapp.getMchId()).get(0);
			Logger.verifyEquals(remarkBean.getMark(), defmchapp.getRemark(), "验证mark");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Remark_002() {
		Logger.start(true,"不输入mchid失败");
		try {
			remarkCall.setData(remarkBean);
			remarkCall.callService();			
			Logger.verifyEquals("400", remarkCall.getString("code"), "验证返回code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	

	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_Remark_003() {
		Logger.start(true,"不输入mark失败");
		try {
			//没有Mark的情况下不会修改为null
			DefGodMchWapper DefGodMchWapper=new DefGodMchWapper();
			Mchapp defmchapp = DefGodMchWapper.selectMchappByExample(null).get(0);
//			remarkBean.setMark("testmark"+TestDataManager.getRandomIntNum(3));
			remarkBean.setMchId(defmchapp.getMchId());
			remarkCall.setData(remarkBean);
			remarkCall.callService();			
			Logger.verifyEquals("200", remarkCall.getString("code"), "验证返回code");
			defmchapp = DefGodMchWapper.selectMchappByExample(defmchapp.getMchId()).get(0);
			Logger.verifyNotNull(defmchapp.getRemark(), "验证mark不为空");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}